//
//  DFParameter.m
//  dfCommandBuilder
//
//  Created by Tom Booth on 31/05/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "DFParameter.h"


@implementation DFParameter

@synthesize name;
@synthesize description;
@synthesize type;

@synthesize useInResponse;
@synthesize manditory;
@synthesize isSearchNumber;


- (BOOL) isEqual:(id) item {

	return ([[item name] compare:[self name]] == NSOrderedSame );
	
}

- (NSString*) typeToCType {
	NSString *ctype;
	
	switch (type) {
		case DFStringParameter:
			ctype = @"char *";
			break;
		case DFNumberParameter:
			ctype = @"int";
			break;
		case DFBooleanParameter:
			ctype = @"int";
			break;
		case DFTimeParameter:
			ctype = @"df_time *";
			break;
		case DFDateParameter:
			ctype = @"df_date *";
			break;
		case DFAddressParameter:
			ctype = @"char *";
			break;
		case DFLongParameter:
			ctype = @"long";
			break;
		default:
			break;
	}
	
	return ctype;
}




+ (DFParameterType) getTypeFromString:(NSString*) string {
	if ([string caseInsensitiveCompare:@"string"] == NSOrderedSame) { return DFStringParameter; }
	else if ([string caseInsensitiveCompare:@"number"] == NSOrderedSame) { return DFNumberParameter; }
	else if ([string caseInsensitiveCompare:@"boolean"] == NSOrderedSame) { return DFBooleanParameter; }
	else if ([string caseInsensitiveCompare:@"time"] == NSOrderedSame) { return DFTimeParameter; }
	else if ([string caseInsensitiveCompare:@"date"] == NSOrderedSame) { return DFDateParameter; }
	else if ([string caseInsensitiveCompare:@"address"] == NSOrderedSame) { return DFAddressParameter; }
	else if ([string caseInsensitiveCompare:@"long"] == NSOrderedSame) { return DFLongParameter; }
	else { return DFUnknownParameter; }
}

+ (NSString*) getStringFromType:(DFParameterType) t {
	if ( t == DFStringParameter ) { return @"String"; }
	else if ( t == DFNumberParameter ) { return @"Number"; }
	else if ( t == DFBooleanParameter ) { return @"Boolean"; }
	else if ( t == DFTimeParameter ) { return @"Time"; }
	else if ( t == DFDateParameter ) { return @"Date"; }
	else if ( t == DFAddressParameter ) { return @"Address"; }
	else if ( t == DFLongParameter ) { return @"Long"; }
	else if ( t == DFUnknownParameter ) { return @"Unknown"; }
	else { return @"blerg"; }
}

@end
